<%@ page contentType="text/html;charset=utf-8" language="java"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@include file="./common/base.jsp" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>用户中心_约导游</title>
<!--css-->
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="css/wutongstyle.css">
<link rel="stylesheet" type="text/css" href="city/citySelector.css">

<script src="city/citySelector.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript" src="My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" src="js/plupload.full.min.js"></script>
<script type="text/javascript" src="js/qiniu.js"></script>
</head>
<body>
<!--head begin-->
<%@ include  file="./common/header.jsp"%>
<!--nav end--> 
<!--content begin-->
<div class="wt_content">
  <dl class="yuedaoyou">
	<%@ include  file="./common/header2.jsp"%><dd>
    <dd>
      <div class="daoyou_info clearfix">
        <div class="xx_box">
          <div class="tainfobox yonghu">
            <h3 id="tuan"><i class="i_co"></i>我的资料</h3>
            <form id="lxsUserId">
            <table width="100%" border="0" cellspacing="0" cellpadding="0" class="biaodan" id="travelorgInfoId">
              <tr>
                <td><input type="hidden" value="" id="pkId"></td>
              </tr>
              <tr>
                <td class="title">旅行社名称：</td>
                <td><input type="text" name="name" id="nameId" value=""></td>
              </tr>
              <tr>
                <td class="title">许可证号：</td>
                <td><input type="text" name="licnum" id="licnumId" value=""></td>
              </tr>
               <tr>
                <td class="title">资格证号：</td>
                <td><input type="text" name="buslicnum" id="buslicnumId" value=""></td>
              </tr>
              <tr>
                <td class="title">法人：</td>
                <td><input type="text" name=""contact id="contactId" value=""></td>
              </tr>
              <tr>
                <td class="title">联系电话：</td>
                <td><input type="text" name="phone" id="phoneId" value=""></td>
              </tr>
              <tr>
                <td class="title">所在城市：</td>
                <td><input type="text" name="szCity" id="szCityId" value="" class="cityinput" placeholder=""></td>
              </tr>
              <tr>
                <td class="title">成立时间：</td>
                <td><input type="text" id="createTimeId" class="Wdate" value="" onClick="WdatePicker()"></td>
              </tr>
              <tr>
                <td class="title">级别：</td>
                <td><input type="text" name="levelName" id="levelId" value=""></td>
              </tr>
              <tr>
                <td class="title">网址：</td>
                <td><input type="text" name="siteName" id="siteId" value=""></td>
              </tr>
              <tr>
                <td class="title">电子信箱：</td>
                <td><input type="text" name="email" id="emailId" value=""></td>
              </tr>
              <tr >
                <td class="title">企业LOGO：</td>
                <td id="uploadImageUserId">
        			
				 </td>
              </tr>
              <tr>
                <td class="title">密码：</td>
                <td><input type="text" name="pass" id="passId" value="">
                  <font>如不需要修改，请留空</font></td>
              </tr>
              <tr>
                <td class="title">确认密码：</td>
                <td><input type="text" name="confirmPass" id="confirmPassId" value="">
                  <font>如不需要修改，请留空</font></td>
              </tr>
              <tr>
                <td class="title">旅行社简介：</td>
                <td><textarea id="descriptionId" name="" cols="" rows=""></textarea></td>
              </tr>
              <tr>
                <td>&nbsp;</td>
                <td><button type="button" value="确    认" onclick="modifyTravelorgDetail()">确    认</button></td>
              </tr>
            </table>
            </form>
            <form id="personUserId">
            <table width="100%" border="0" cellspacing="0" cellpadding="0" class="biaodan" id="personalInfoId">
              <tr>
                <td><input type="hidden" value="" id="pk5Id"></td>
              </tr>
              <tr>
                <td class="title">姓名：</td>
                <td><input type="text" id="name5Id" name="name5" value=""></td>
              </tr>
              <tr>
                <td class="title">身份证号：</td>
                <td><input type="text" id="idnum5Id" name="idnum5" value=""></td>
              </tr>
               <tr>
                <td class="title">手机号码：</td>
                <td><input type="text" id="phone5Id" name="phone5" value=""></td>
              </tr>
              <tr>
                <td class="title">电子邮箱：</td>
                <td><input type="text" id="email5Id" name="email5" value=""></td>
              </tr>
            
             
              <tr id = "up_bg_img_parent5Id">
                <td class="title">个人LOGO：</td>
                <td  id="uploadImagePersonalId">
	               <!--  <div class="col-md-12">
			            <div id="up_bg_img_parent5Id">
			                <a class="btn btn-default " id="up_bg_5img" style="margin-left:-15px;" href="#" >
			                    <i class="glyphicon glyphicon-plus"></i>
			                    <sapn>选择文件</sapn>
			                </a>
			            </div>
			        </div>
       
	                <input type="hidden" id="backgroundVal5Id"></input>
	                <div class="process-bar skin-blue" style="display:none;" id="processbar5Id">
					     <div class="pb-wrapper">
					     <div class="pb-highlight"></div>
					     <div class="pb-container">
					     <div class="pb-text" id="processbarVal51Id">0%</div>
					     <div class="pb-value" id="processbarVal52Id" style="width:0%"></div>
					     </div>
					     </div>
					</div> -->
					
				</td>
              </tr>
              <tr>
                <td class="title">密码：</td>
                <td><input type="text" name="pass5" id="pass5Id" value="">
                  <font>如不需要修改，请留空</font></td>
              </tr>
              <tr>
                <td class="title">确认密码：</td>
                <td><input type="text" name="confirmPass5" id="confirmPass5Id" value="">
                  <font>如不需要修改，请留空</font></td>
              </tr>
              <tr>
                <td class="title">个人简介：</td>
                <td><textarea id="description5Id" name="" cols="" rows=""></textarea></td>
              </tr>
              <tr>
                <td>&nbsp;</td>
                <td><button type="button" value="确    认" onclick="modifyPersonalDetail()">确    认</button></td>
              </tr>
            </table>
            </form>
          </div>
        </div>
        <div class="zp"><img id="headImgId" src="" width="185" height="90" />
          <div class="tel">
            <h4>快捷菜单</h4>
            <ul class="quick">
              <li><a href="lxslogin_1.jsp">发布新团信息</a></li>
              <li><a href="lxslogin.jsp" >团信息列表</a></li>
              <li><a href="lxslogin_2.jsp" >新发团信息</a></li>
              <li><a href="lxslogin_3.jsp" >已申请信息</a></li>
              <li><a href="lxslogin_4.jsp" >已确认信息</a></li>
              <li><a href="lxslogin_6.jsp" >已发团信息</a></li>
              <li><a href="lxslogin_5.jsp" class="on">我的资料</a></li>
              <li><a href="lxslogin_7.jsp" >站内短信列表</a></li>
            </ul>
          </div>
        </div>
      </div>
    </dd>
  </dl>
</div>
<!--content end
<div class="tipc" style="display:none;" id="showWanShanId"><a href="lxslogin_5.jsp">请先完善注册资料</a>
<a href="javascript:closeShowWanShan()">关闭</a>
</div>--> 
<!--footer begin-->
<%@ include  file="./common/footer.jsp"%>
<!--footer end-->
</body>
<script type="text/javascript">
/* function closeShowWanShan(){
	document.getElementById("showWanShanId").style.display="none";
}
function showWanShanFuc(){
	if(showWanShan==0){
		document.getElementById("showWanShanId").style.display="block";
		refreshWanShan();
	}else{
		document.getElementById("showWanShanId").style.display="none";
	}
} */
function lxsUserValidate() {
	return $('#lxsUserId').validate({  
        rules:{  
        	name:'required', 
        	licnum:'required', 
        	buslicnum:'required', 
        	contact:'required', 
        	phone:'required',
        	szCity:'required',
        	//levelName:'digits',
	        siteName:'url',
	        email:{
        		required:true,
        		email:true
            },
            pass:{
            	minlength:6
            },
            confirmPass:{
            	minlength:6
            }
        		
            },  
        messages:{  
        	name:'&nbsp;&nbsp;旅行社不能为空',
        	licnum:'&nbsp;&nbsp;许可证号不能为空',  
        	buslicnum:'&nbsp;&nbsp;资格证号不能为空', 
        	contact:'&nbsp;&nbsp;请填写法人',
        	phone:'&nbsp;&nbsp;请填写手机号',
        	szCity:'&nbsp;&nbsp;请填写所在城市',
        	//levelName:'&nbsp;&nbsp;必须是整数哦',
	        siteName:'&nbsp;&nbsp;请填写正确网址,例:http://www.baidu.com',
	        email:{
        		required:'&nbsp;&nbsp;请填写邮箱',
        		email:'&nbsp;&nbsp;请填写正确的邮箱格式,例:xxx@xxx.com'
        	 },
        	 pass:{
        		 minlength:$.validator.format("密码不能小于{0}个字 符")
        	 },
        	 confirmPass:{
        		 minlength:$.validator.format("密码不能小于{0}个字 符")
        	 }
            }  
    });  
}
function personalUserValidate() {
	return $('#personUserId').validate({  
        rules:{  
        	name5:'required', 
        	idnum5:'required', 
        	phone5:'required',
        	email5:{
        		required:true,
        		email:true
            },
            pass5:{
            	minlength:6
            },
            confirmPass5:{
            	minlength:6
            }
        },
        messages:{  
        	name5:'&nbsp;&nbsp;姓名不能为空',
        	idnum5:'&nbsp;&nbsp;身份证不能为空',  
        	phone5:'&nbsp;&nbsp;请填写手机号',
        	email5:{
        		required:'&nbsp;&nbsp;请填写邮箱',
        		email:'&nbsp;&nbsp;请填写正确的邮箱格式,例:xxx@xxx.com'
        	 },
        	 pass5:{
        		 minlength:$.validator.format("密码不能小于{0}个字 符")
        	 },
        	 confirmPass5:{
        		 minlength:$.validator.format("密码不能小于{0}个字 符")
        	 }
        } 
    });  
}
function uploadStr() {
	return "<div class=\"col-md-12\">"+
				    "<div id=\"up_bg_img_parentId\">"+
				    "<a class=\"btn btn-default \" id=\"up_bg_img\" style=\"margin-left:-15px;\" href=\"#\" >"+
				        "<i class=\"glyphicon glyphicon-plus\"></i>"+
				        "<sapn>选择文件</sapn>"+
				    "</a>"+
				"</div>"+
				"</div>"+
				
				"<input type=\"hidden\" id=\"backgroundValId\"></input>"+
				"<div class=\"process-bar skin-blue\" style=\"display:none;\" id=\"processbarId\">"+
				     "<div class=\"pb-wrapper\">"+
				     "<div class=\"pb-highlight\"></div>"+
				     "<div class=\"pb-container\">"+
				     "<div class=\"pb-text\" id=\"processbarVal1Id\">0%</div>"+
				     "<div class=\"pb-value\" id=\"processbarVal2Id\" style=\"width:0%\"></div>"+
				     "</div>"+
				     "</div>"+
				"</div>";
}
$(function(){
	new Vcity.CitySelector({input:'szCityId'});
	if(loginUserType==0){//旅行社
		$("#travelorgInfoId").show();
		$("#personalInfoId").hide();
		$("#uploadImageUserId").html(uploadStr());
		loadImgOpt("up_bg_img_parentId","backgroundValId","up_bg_img","pkId","processbarId","processbarVal1Id","processbarVal2Id");
		loadTravelorgDetail();
	}else{//个人
		$("#travelorgInfoId").hide();
		$("#personalInfoId").show();
		$("#uploadImagePersonalId").html(uploadStr());
		loadImgOpt("up_bg_img_parentId","backgroundValId","up_bg_img","pk5Id","processbarId","processbarVal1Id","processbarVal2Id");

		//loadImgOpt("up_bg_img_parent5Id","backgroundVal5Id","up_bg_5img","pk5Id","processbar5Id","processbarVal51Id","processbarVal52Id");
		loadPersonalDetail();
	}
	//showWanShanFuc();
	
});
function uploadHeadImg(backgroundValId,pkId){
	var id = $("#"+pkId+"").val();
	var photo = $("#"+backgroundValId+"").val().replace(imgDomain,"");
	objp= "{\"id\":\""+id+"\","+
    "\"photo\":\""+photo+"\""+
    "}";
	$.ajax({
	url: '${path}/core/modifyUserDetail',
	type: 'POST',
	timeout: 30000,
	cache : false,
	data :objp,
	async: false,
	dataType:"json",      
	contentType:"application/json",   
	success:function(msg){
	 alert("logo设置完成");
	},
	failure:function(msg){
	  alert(eval('('+msg.responseText+')').error_text);
			
	},
	error:function(msg){
	  alert(eval('('+msg.responseText+')').error_text); 
	}
	});
}
function modifyTravelorgDetail(){
	if(lxsUserValidate().form()){
	}else{
		return;
	}
	var id = $("#pkId").val();
	var name = $("#nameId").val();
	var email = $("#emailId").val();
	var licnum = $("#licnumId").val();
	var city = $("#szCityId").val();
	var buslicnum = $("#buslicnumId").val();
	var phone = $("#phoneId").val();
	var contact = $("#contactId").val();
	var createTime = $("#createTimeId").val();
	var level  = $("#levelId").val();
	var site  = $("#siteId").val();
	var description  = $("#descriptionId").val();
	var pass = $("#passId").val();
	var confirmpass = $("#confirmPassId").val();
	if(pass!=null && pass!=""){
		if(confirmpass!=pass) {
			alert("两次密码不一致");return;
		}
	}
	//var photo = $("#backgroundValId").val().replace(imgDomain,"");
	objp= "{\"id\":\""+id+"\","+
		         "\"name\":\""+name+"\","+
		         "\"licnum\":\""+licnum+"\","+
		         "\"city\":\""+city+"\","+
		         "\"phone\":\""+phone+"\","+
		         "\"buslicnum\":\""+buslicnum+"\","+
		         "\"contact\":\""+contact+"\","+
		         "\"createTime\":\""+createTime+"\","+
		         "\"level\":\""+level+"\","+
		         "\"email\":\""+email+"\","+
		        // "\"photo\":\""+photo+"\","+
		         "\"site\":\""+site+"\","+
		         "\"password\":\""+confirmpass+"\","+
		         "\"description\":\""+escape(description)+"\""+
		         "}";
	$.ajax({
		  url: '${path}/core/modifyUserDetail',
		  type: 'POST',
		  timeout: 30000,
		  cache : false,
	      data :objp,
	      async: false,
	      dataType:"json",      
          contentType:"application/json",   
		  success:function(msg){
			  alert("ok");
		  },
		   failure:function(msg){
			   alert(eval('('+msg.responseText+')').error_text);
		   		
		   },
		   error:function(msg){
			   alert(eval('('+msg.responseText+')').error_text); 
		   }
	});
}
function loadTravelorgDetail(){
	var objp={};
	$.ajax({
		  url: '${path}/core/getAccountDetail',
		  type: 'POST',
		  timeout: 30000,
		  cache : false,
	      data :objp,
	      async: false,
	      dataType:"json",      
        contentType:"application/json",   
	     // contentType: "application/json; charset=utf-8",
		  success:function(msg){
			  formatTravelorgDetail(msg.userDetail);
		  },
		   failure:function(msg){
			   alert(eval('('+msg.responseText+')').error_text);
		   		
		   },
		   error:function(msg){
			   alert(eval('('+msg.responseText+')').error_text); 
		   }
	});
}
function formatTravelorgDetail(data){
	if(data){
		$("#pkId").val(data.id);
		$("#nameId").val(data.name);
		$("#licnumId").val(data.licnum);
		$("#buslicnumId").val(data.buslicnum);
		$("#szCityId").val(data.city);
		$("#contactId").val(data.contact);
		$("#phoneId").val(data.phone);
		$("#createTimeId").val(data.createTime);
		$("#levelId").val(data.level);
		$("#siteId").val(data.site);
		$("#descriptionId").val(data.description);
		//$("#workyearId").val(data.workyear);
		$("#backgroundValId").val(data.photo);
		$("#emailId").val(data.email);
		$("#headImgId").attr("src",imgDomain+data.photo);
	}
}


function modifyPersonalDetail(){
	if(personalUserValidate().form()){
	}else{
		return;
	}
	var id = $("#pk5Id").val();
	var name = $("#name5Id").val();
	var email = $("#email5Id").val();
	var idnum = $("#idnum5Id").val();
	var phone = $("#phone5Id").val();
	var description  = $("#description5Id").val();
	//var photo = $("#backgroundVal5Id").val().replace(imgDomain,"");
	var pass = $("#pass5Id").val();
	var confirmpass = $("#confirmpass5Id").val();
	if(pass!=null && pass!=""){
		if(confirmpass!=pass) {
			alert("两次密码不一致");return;
		}
	}
	objp= "{\"id\":\""+id+"\","+
		         "\"name\":\""+name+"\","+
		         "\"idnum\":\""+idnum+"\","+
		         "\"phone\":\""+phone+"\","+
		         "\"email\":\""+email+"\","+
		         "\"password\":\""+confirmpass+"\","+
		         "\"description\":\""+escape(description)+"\""+
		         "}";
	$.ajax({
		  url: '${path}/core/modifyUserDetail',
		  type: 'POST',
		  timeout: 30000,
		  cache : false,
	      data :objp,
	      async: false,
	      dataType:"json",      
          contentType:"application/json",   
		  success:function(msg){
			  alert("ok");
		  },
		   failure:function(msg){
			   alert(eval('('+msg.responseText+')').error_text);
		   		
		   },
		   error:function(msg){
			   alert(eval('('+msg.responseText+')').error_text); 
		   }
	});
}

function loadPersonalDetail(){
	var objp={};
	$.ajax({
		  url: '${path}/core/getAccountDetail',
		  type: 'POST',
		  timeout: 30000,
		  cache : false,
	      data :objp,
	      async: false,
	      dataType:"json",      
        contentType:"application/json",   
	     // contentType: "application/json; charset=utf-8",
		  success:function(msg){
			  formatPersonalDetail(msg.userDetail);
		  },
		   failure:function(msg){
			   alert(eval('('+msg.responseText+')').error_text);
		   		
		   },
		   error:function(msg){
			   alert(eval('('+msg.responseText+')').error_text); 
		   }
	});
}
function formatPersonalDetail(data){
	if(data){
		$("#pk5Id").val(data.id);
		$("#name5Id").val(data.name);
		$("#idnum5Id").val(data.idnum);
		$("#phone5Id").val(data.phone);
		$("#description5Id").val(data.description);
		//$("#workyearId").val(data.workyear);
		$("#backgroundVal5Id").val(data.photo);
		$("#email5Id").val(data.email);
		$("#headImgId").attr("src",imgDomain+data.photo);
	}
}
//*********************start****************************
function getUpToken() {
	var objp={};
	var token = "";
	 $.ajax({
		  url: '${path}/core/getUpToken',
		  type: 'POST',
		  timeout: 30000,
		  cache : false,
	      data :objp,
	      async: false,
		  success:function(msg){
			  //setCardInfo(msg.cardInfo)
			  token =  msg.uptoken;
		   },
		   failure:function(msg){
			   alert(eval('('+msg.responseText+')').error_text);
		   		
		   },
		   error:function(msg){
			   alert(eval('('+msg.responseText+')').error_text); 
		   }
	});
	 return token;
}
function loadImgOpt(parentId,backgroundValId,btn,pkId,processbarId,processbarVal1Id,processbarVal2Id) {
var wei7 = generateMixed(7); 	
//var uptokenStr = getUpToken();
var uploader = Qiniu.uploader({
    runtimes: 'html5,flash,html4',    //上传模式,依次退化
    browse_button: btn,       //上传选择的点选按钮，**必需**
    uptoken_url: '${path}/core/getUpToken',            //Ajax请求upToken的Url，**强烈建议设置**（服务端提供）
    // downtoken_url: '/downtoken',
    // Ajax请求downToken的Url，私有空间时使用,JS-SDK将向该地址POST文件的key和domain,服务端返回的JSON必须包含`url`字段，`url`值为该文件的下载地址
   // uptoken : uptokenStr, //若未指定uptoken_url,则必须指定 uptoken ,uptoken由其他程序生成
    // unique_names: true, // 默认 false，key为文件名。若开启该选项，SDK会为每个文件自动生成key（文件名）
    // save_key: true,   // 默认 false。若在服务端生成uptoken的上传策略中指定了 `sava_key`，则开启，SDK在前端将不对key进行任何处理
    domain: 'http://guide.qiniudn.com/',   //bucket 域名，下载资源时用到，**必需**
    container: parentId,//document.getElementById(parentId),          //上传区域DOM ID，默认是browser_button的父元素，
    max_file_size: '100mb',           //最大文件体积限制
    flash_swf_url: 'js/Moxie.swf',  //引入flash,相对路径
    silverlight_xap_url:'js/Moxie.xap',
    max_retries: 2,                   //上传失败最大重试次数
    //dragdrop: true,                   //开启可拖曳上传
    //drop_element: 'container',        //拖曳上传区域元素的ID，拖曳文件或文件夹后可触发上传
    chunk_size: '4mb',                //分块上传时，每片的体积
    auto_start: true,   
    unique_names: false ,
    save_key: false,//选择文件后自动上传，若关闭需要自己绑定事件触发上传,
    init: {
        'FilesAdded': function(up, files) {
          //  plupload.each(files, function(file) {
                // 文件添加进队列后,处理相关的事情
            	//uploader.start();
            	//return true;
            //});
        },
        'BeforeUpload': function(up, file) {
               // 每个文件上传前,处理相关的事情
        	 $('#'+processbarId).css("display","inline-block");
        },
        'UploadProgress': function(up, file) {
               // 每个文件上传时,处理相关的事情
            $('#'+processbarVal1Id).html(file.percent + "%");
            $('#'+processbarVal2Id).css("width",file.percent + "%");
        },
        'FileUploaded': function(up, file, info) {
               // 每个文件上传成功后,处理相关的事情
               // 其中 info 是文件上传成功后，服务端返回的json，形式如
               // {
               //    "hash": "Fh8xVqod2MQ1mocfI4S4KpRL6D98",
               //    "key": "gogopher.jpg"
               //  }
               // 参考http://developer.qiniu.com/docs/v6/api/overview/up/response/simple-response.html

                //var domain = up.getOption('domain');
               /// var res = parseJSON(info);
               // var sourceLink = domain + res.key;// 获取上传成功后的文件的Url
              
              // $("#backgroundId").attr("src",imgDomain+loginUserId+"_"+wei7+file.name);
              // $("#backgroundId").css("width",185);
               $("#"+backgroundValId).val(loginUserId+"_"+wei7+file.name);
               $("#headImgId").attr("src",imgDomain+loginUserId+"_"+wei7+file.name);
               uploadHeadImg(backgroundValId,pkId);
               
        },
        'Error': function(up, err, errTip) {
        	 $('#'+processbarId).css("display","none");
        	alert(err.code+"--"+err.message);
               //上传出错时,处理相关的事情
        },
        'UploadComplete': function() {
               //队列文件处理完毕后,处理相关的事情
        	 $('#'+processbarId).css("display","none");
               
        },
        'Key': function(up, file) {
            // 若想在前端对每个文件的key进行个性化处理，可以配置该函数
            // 该配置必须要在 unique_names: false , save_key: false 时才生效
            var key = loginUserId+"_"+wei7+file.name;
            // do something with key here
            return key
        }
    }
});
}
/************end*******************/
</script>
</html>
